home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / asmlook.zip / ASMLOOK.ASM next >
Assembly Source File  |  1993-04-19  |  5KB  |  157 lines

  1. cr  equ 13
  2. lf  equ 10
  3. bptr  equ byte ptr
  4. ofs  equ offset
  5.  
  6. jmps            macro   loc
  7.                 jmp     short loc
  8.                 endm
  9.  
  10. code  segment
  11.   assume cs:code
  12.  
  13.   org 100h
  14. begin:  jmp start
  15.  
  16. numblocks dw ?  ; store number of 16k blocks for search
  17. searchstr dw ?  ; store address of search string
  18. strlen  dw ?  ; store length of search string
  19.  
  20. h2a  proc near  ; clever code that converts 0 - f in al
  21.   add al,90h  ;   into ASCII 0 - 9, A - F in al
  22.   daa
  23.   adc al,40h
  24.   daa
  25.   ret
  26. h2a  endp
  27.  
  28. write_al proc near  ; write hex contents of al to screen
  29.   push ax  ; save registers used
  30.   push cx
  31.   push dx
  32.   push ax  ; save lower nybble
  33.   mov cl,4  ; shift 4 bits
  34.   shr al,cl  ; move high nybble to low nybble
  35.   call h2a  ; convert to ASCII
  36.   mov dl,al  ; send character to output device
  37.   mov ah,2  ;   with DOS function 2
  38.   int 21h
  39.   pop ax  ; get lower nybble
  40.   and al,0fh  ; isolate nybble
  41.   call h2a  ; convert to ASCII
  42.   mov dl,al  ; send character to output device
  43.   mov ah,2  ;   with DOS function 2
  44.   int 21h
  45.   pop dx  ; restore registers
  46.   pop cx
  47.   pop ax
  48.   ret
  49. write_al endp
  50.  
  51. write_ax proc near  ; write hex contents of ax to screen
  52.   push ax  ; save register
  53.   mov al,ah  ; write high byte first
  54.   call write_al ; ASCII value of high byte to std out
  55.   pop ax  ; recover
  56.   call write_al ; ASCII value of low byte to std out
  57.   ret
  58. write_ax endp
  59.  
  60. syntax  db cr,lf,'   LOOK version 1.0',cr,lf,cr,lf
  61.   db '   The correct syntax for LOOK is "LOOK something",'
  62.   db ' where "something" is a',cr,lf,'   string (any string'
  63.   db ' at all) to be searched for in DOS memory.  DOS keeps'
  64.   db cr,lf,'   a record of the command line in several '
  65.   db 'places so LOOK will list several',cr,lf,'   addresses'
  66.   db ' at least; more if matches are found in other memory '
  67.   db 'locations.',cr,lf,'$'
  68.  
  69. start:  mov si,80h  ; get command line character count
  70.   cmp bptr[si],0 ; anything on command line
  71.   jnz do_look  ; yes, look for item
  72. do_syntax: mov dx,ofs syntax ; point to syntax message
  73.   mov ah,9  ; send it to console
  74.   int 21h
  75.   jmp exit  ; done, leave
  76.  
  77. do_look: int 12h  ; get system memory
  78.   mov cl,4  ; compute number of 16k blocks
  79.   shr ax,cl
  80.   mov numblocks,ax ; store as number of blocks for search
  81.   mov si,81h  ; address command line
  82. next_char: lodsb   ; get character from command line
  83.   cmp al,' '  ; a space?
  84.   je next_char ; yes, ignore
  85.   cmp al,9  ; a tab char?
  86.   je next_char ; again ignore
  87.   dec si  ; point again to first string char
  88.   mov searchstr,si ; store point of string origin
  89.   mov di,si  ; search for cr at end of command line
  90.   mov al,cr
  91.   mov cx,128
  92.   repne scasb
  93.   sub di,si  ; compute search string length
  94.   dec di  ; (not to include cr)
  95.   jz do_syntax
  96.   mov strlen,di
  97.   mov dl,cr  ; print crlf
  98.   mov ah,2
  99.   int 21h
  100.   mov dl,lf
  101.   int 21h
  102.   xor ax,ax  ; zero
  103.   mov es,ax  ;   to es
  104.   xor di,di  ; start search at 0:0
  105.   mov bx,strlen ; length of search string to bx
  106.   mov dx,searchstr ; search string address to dx
  107.  
  108. lookagain: cmp di,16384 ; search offset at or beyond 16k?
  109.   jae bumpseg  ; yes, move to next search segment
  110.   mov si,dx  ; load address of search string
  111.   mov cx,bx  ;   and its length
  112.   repe cmpsb  ; is it a match?
  113.   jne lookagain ; no, not found; try again
  114.  
  115.   mov dl,' '  ; print two spaces
  116.   mov ah,2
  117.   int 21h
  118.   int 21h
  119.   sub di,bx  ; yes, point again to matched string
  120.   mov bx,di  ; compute normalized segment of match:
  121.   mov cl,4  ;   divide offset by 16
  122.   shr bx,cl  ;   to get paragraphs in bx
  123.   mov ax,es
  124.   add ax,bx
  125.   call write_ax ; print normalized segment
  126.   mov dl,':'  ; print colon
  127.   mov ah,2
  128.   int 21h
  129.   mov ax,di  ; compute normalized offset of match:
  130.   shl bx,cl  ;   multiply paragraphs by 16
  131.   sub ax,bx  ;   so get offset within paragraph
  132.   call write_ax ; print normalized offset
  133.   mov dl,cr  ; print crlf
  134.   mov ah,2
  135.   int 21h
  136.   mov dl,lf
  137.   int 21h
  138.   mov bx,strlen ; reload length of search string
  139.   mov dx,searchstr ; reload search string address
  140.   add di,bx  ; restore di value
  141.   jmps lookagain ; continue search
  142.  
  143. exit:  mov ax,4c00h ; exit with error level of 0
  144.   int 21h
  145.  
  146. bumpseg: sub di,16384 ; reduce offset by 16k for next segment
  147.   mov ax,es  ; last used search segment
  148.   add ax,400h  ; compute next used search segment
  149.   dec numblocks ; looked far enough yet?
  150.   jz exit  ; yes, done
  151.   mov es,ax  ; no, try next segment
  152.   jmps lookagain ; continue looking
  153.  
  154. code  ends
  155.   end begin
  156.  
  157.